package nina.yiyou.performance.s11collect.input

import nina.yiyou.salary.input.util.ExcelReadOpener
import org.apache.poi.ss.usermodel.Sheet
import org.apache.poi.ss.usermodel.Workbook

import java.nio.file.Path

class CollectFilledReader {

  interface Filler {

    String employeeId()

    String employeeName()

    List<Eval> selfEval()

    Map<String, List<Eval>> otherEval()
  }

  // 代表一项评分
  interface Eval {

    String evaluateeId()

    String evaluateeName()

    String fillerId()

    String fillerName()

    String type()

    String group()

    String key()

    Object value()
  }

  CollectFilledReader(Path excelPath) {
    _excelPath = excelPath
  }

  Filler read() {
    def fileName = _excelPath.getFileName().toString()
    println(_excelPath)

    String[] fillerInfo = fileName.split('\\.')[0].split('_')
    String employeeId = fillerInfo[1]
    String employeeName = fillerInfo[2]

    Workbook book = new ExcelReadOpener(_excelPath).openXlsx()
    Sheet sheet = book.getSheetAt(0)

    List selfEval = new SelfEvalExtractor(sheet, employeeId, employeeName).extract()
    Map otherEval = new OtherEvalExtractor(sheet, employeeId, employeeName).extract()

    book.close()

    return new Filler() {
      @Override
      String employeeId() {
//        return "[#漏填工号!${employeeName}]".toString()
        return employeeId
      }

      @Override
      String employeeName() {
        return employeeName
      }

      @Override
      List<Eval> selfEval() {
        return selfEval
      }

      @Override
      Map<String, List<Eval>> otherEval() {
        return otherEval
      }
    }
  }

  private final Path _excelPath
}
